package com.cg.design.graphicdesignpattern.factory.idcard;

import com.cg.design.graphicdesignpattern.factory.framework.Factory;
import com.cg.design.graphicdesignpattern.factory.framework.Product;

import java.util.Hashtable;

/**
 * 表示ID卡的生成工厂
 *
 * @program: LeetCode->IDCardFactory
 * @description: 表示ID卡的生成工厂
 * @author: cg
 * @create: 2022-03-19 15:01
 **/
public class IDCardFactory extends Factory {

    private Hashtable<Integer, String> database = new Hashtable<>();
    private int serial = 100;

    @Override
    protected synchronized Product createProduct(String owner) {
        return new IDCard(owner, serial++);
    }

    @Override
    protected void registerProduct(Product product) {
        IDCard idCard = (IDCard) product;
        database.put(idCard.getSerial(), idCard.getOwner());
    }

    public Hashtable<Integer, String> getDatabase() {
        return database;
    }

}
